# -*- coding: utf-8 -*-
"""
-------------------------------------------------
Project Name: luffcity study project
File Name: common.py
Author: kij
Create Date: 2021/2/23
-------------------------------------------------
"""


# 传递角色名称
def logon(role):
	from view import admin_view, teacher_view, student_view
	# 装饰器
	def logon_func(func):
		def inner():
			if role == 'admin':
				# 判断有没有登录的用户名
				if admin_view.logon_state['user']:
					res = func()
					return res
				else:
					admin_view.logon()
			elif role == 'student':
				if student_view.logon_state['user']:
					res = func()
					return res
				else:
					student_view.logon()
			elif role == 'teacher':
				if teacher_view.logon_state['user']:
					res = func()
					return res
				else:
					teacher_view.logon()
			else:
				print("没有权限")

		return inner

	return logon_func
